package com.github.mustfun.mybatis.plugin.setting;

import com.intellij.ui.CheckBoxList;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.components.JBTextField;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @date 2018/6/13
 * @since 1.0
 */
@Setter
@Getter
public class ConnectDbSetting {
    private JTextField address;
    private JTextField userName;
    private JTextField password;
    private JTextField port;
    private JButton connectButton;
    private JPanel mainPanel;
    private JLabel addressText;
    private JLabel portText;
    private JLabel userNameText;
    private JLabel passwordText;
    private JPanel listPanel;
    private JBScrollPane scrollPaneList;
    private CheckBoxList<String> tableCheckBox;
    private JTextField dbName;
    private JLabel dbNamePanel;
    private JBScrollPane templatePanel;
    private CheckBoxList<Integer> templateCheckbox;
    private JPanel configPanel;
    private JPanel generatePanel;
    private JBLabel tablePrefixLabel;
    private JBTextField tablePrefixInput;
    private JButton daoButton;
    private JBLabel daoLabel;
    private JBTextField daoInput;
    private JBLabel mapperLabel;
    private JBTextField mapperInput;
    private JButton mapperButton;
    private JBLabel poLabel;
    private JBTextField poInput;
    private JButton poButton;
    private JPanel daoPanel;
    private JPanel mapperPanel;
    private JPanel tablePrefixPanel;
    private JPanel poPanel;
    private JBLabel controllerLabel;
    private JBTextField controllerInput;
    private JPanel controllerPanel;
    private JButton controllerButton;
    private JPanel servicePanel;
    private JBTextField serviceInput;
    private JButton serviceButton;
    private JBLabel serviceLabel;

    public ConnectDbSetting() {
        port.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                int keyChar = e.getKeyChar();
                if (!(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9)) {
                    e.consume(); //关键，屏蔽掉非法输入
                }
            }
        });
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayoutManager(2, 11, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.setPreferredSize(new Dimension(870, 400));
        address = new JTextField();
        address.setText("localhost");
        mainPanel.add(address, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0,
                false));
        userName = new JTextField();
        userName.setText("root");
        mainPanel.add(userName, new GridConstraints(0, 7, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0,
                false));
        addressText = new JLabel();
        addressText.setText("地址");
        mainPanel.add(addressText, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        password = new JTextField();
        password.setText("root");
        mainPanel.add(password, new GridConstraints(0, 9, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0,
                false));
        port = new JTextField();
        port.setText("3306");
        mainPanel.add(port, new GridConstraints(0, 3, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0,
                false));
        portText = new JLabel();
        portText.setText("端口");
        mainPanel.add(portText, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        userNameText = new JLabel();
        userNameText.setText("用户名");
        mainPanel.add(userNameText, new GridConstraints(0, 6, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        passwordText = new JLabel();
        passwordText.setText("密码");
        mainPanel.add(passwordText, new GridConstraints(0, 8, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        connectButton = new JButton();
        connectButton.setText("连接");
        mainPanel.add(connectButton, new GridConstraints(0, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        listPanel = new JPanel();
        listPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.add(listPanel, new GridConstraints(1, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        scrollPaneList = new JBScrollPane();
        scrollPaneList.setToolTipText("拿到的表");
        listPanel.add(scrollPaneList, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        tableCheckBox = new CheckBoxList();
        scrollPaneList.setViewportView(tableCheckBox);
        dbNamePanel = new JLabel();
        dbNamePanel.setText("数据库名");
        mainPanel.add(dbNamePanel, new GridConstraints(0, 4, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        dbName = new JTextField();
        dbName.setText("biwann");
        mainPanel.add(dbName, new GridConstraints(0, 5, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0,
                false));
        templatePanel = new JBScrollPane();
        mainPanel.add(templatePanel, new GridConstraints(1, 3, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        templateCheckbox = new CheckBoxList();
        templatePanel.setViewportView(templateCheckbox);
        configPanel = new JPanel();
        configPanel.setLayout(new GridLayoutManager(8, 1, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.add(configPanel, new GridConstraints(1, 4, 1, 6, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        tablePrefixPanel = new JPanel();
        tablePrefixPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(tablePrefixPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        tablePrefixLabel = new JBLabel();
        tablePrefixLabel.setPreferredSize(new Dimension(100, 17));
        tablePrefixLabel.setText("表前缀（可不填）");
        tablePrefixPanel.add(tablePrefixLabel);
        tablePrefixInput = new JBTextField();
        tablePrefixInput.setMargin(new Insets(0, 0, 0, 0));
        tablePrefixInput.setPreferredSize(new Dimension(250, 30));
        tablePrefixInput.setText("");
        tablePrefixPanel.add(tablePrefixInput);
        final Spacer spacer1 = new Spacer();
        configPanel.add(spacer1, new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        daoPanel = new JPanel();
        daoPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(daoPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        daoLabel = new JBLabel();
        daoLabel.setPreferredSize(new Dimension(100, 17));
        daoLabel.setText("Dao层位置");
        daoPanel.add(daoLabel);
        daoInput = new JBTextField();
        daoInput.setMargin(new Insets(0, 10, 0, 0));
        daoInput.setPreferredSize(new Dimension(250, 30));
        daoInput.setText("");
        daoPanel.add(daoInput);
        daoButton = new JButton();
        daoButton.setPreferredSize(new Dimension(20, 30));
        daoButton.setText("...");
        daoPanel.add(daoButton);
        mapperPanel = new JPanel();
        mapperPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(mapperPanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        mapperLabel = new JBLabel();
        mapperLabel.setPreferredSize(new Dimension(100, 17));
        mapperLabel.setText("Mapper层位置");
        mapperPanel.add(mapperLabel);
        mapperInput = new JBTextField();
        mapperInput.setPreferredSize(new Dimension(250, 30));
        mapperPanel.add(mapperInput);
        mapperButton = new JButton();
        mapperButton.setPreferredSize(new Dimension(20, 30));
        mapperButton.setText("...");
        mapperPanel.add(mapperButton);
        poPanel = new JPanel();
        poPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(poPanel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        poLabel = new JBLabel();
        poLabel.setPreferredSize(new Dimension(100, 17));
        poLabel.setText("Model层位置");
        poPanel.add(poLabel);
        poInput = new JBTextField();
        poInput.setPreferredSize(new Dimension(250, 30));
        poPanel.add(poInput);
        poButton = new JButton();
        poButton.setPreferredSize(new Dimension(20, 30));
        poButton.setText("...");
        poPanel.add(poButton);
        controllerPanel = new JPanel();
        controllerPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(controllerPanel, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        controllerLabel = new JBLabel();
        controllerLabel.setPreferredSize(new Dimension(100, 17));
        controllerLabel.setText("Controller层位置");
        controllerPanel.add(controllerLabel);
        controllerInput = new JBTextField();
        controllerInput.setPreferredSize(new Dimension(250, 30));
        controllerPanel.add(controllerInput);
        controllerButton = new JButton();
        controllerButton.setPreferredSize(new Dimension(20, 30));
        controllerButton.setText("...");
        controllerPanel.add(controllerButton);
        servicePanel = new JPanel();
        servicePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
        configPanel.add(servicePanel, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        serviceLabel = new JBLabel();
        serviceLabel.setPreferredSize(new Dimension(100, 17));
        serviceLabel.setText("Service层位置");
        servicePanel.add(serviceLabel);
        serviceInput = new JBTextField();
        serviceInput.setPreferredSize(new Dimension(250, 30));
        servicePanel.add(serviceInput);
        serviceButton = new JButton();
        serviceButton.setPreferredSize(new Dimension(20, 30));
        serviceButton.setText("...");
        servicePanel.add(serviceButton);
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        configPanel.add(panel1, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        generatePanel = new JPanel();
        generatePanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        mainPanel.add(generatePanel, new GridConstraints(1, 10, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return mainPanel;
    }
}
